import { Injectable } from '@angular/core';
@Injectable({
  providedIn: 'root'
})
export class LoginInfoService {

  private logInfo={
    userName:"",
    mobile:"",
    registeAddress:"",
    idCard:"",
    nation:"",
    deleteMark:"",
    unitGuid:"",
    enabledMark:"",
    gender:"",
    birthday:"",
    headIcon:"",
  }

  private token=""

  setInfo(setInfo:any){
    //用于把信息存入
      this.logInfo.headIcon=setInfo.user.headIcon;
      this.logInfo.birthday=setInfo.user.birthday;
      this.logInfo.gender=setInfo.user.gender;
      this.logInfo.enabledMark=setInfo.user.enabledMark;
      this.logInfo.unitGuid=setInfo.user.unitGuid;
      this.logInfo.deleteMark=setInfo.user.deleteMark;
      this.logInfo.nation=setInfo.user.nation;
      this.logInfo.idCard=setInfo.user.idCard;
      this.logInfo.registeAddress=setInfo.user.registeAddress;
      this.logInfo.mobile=setInfo.user.mobile;
      this.logInfo.userName=setInfo.user.userName;
      this.token=setInfo.token;
   
      this.setlocal("user",setInfo.user)
      this.setlocal("token",setInfo.token)
  }

  /***获取基本信息****/
  getInfo(){
    if(!!this.getlocal("user")){//如果不为空 获取
        this.logInfo=this.getlocal("user");
    }

    //获取信息
    return this.logInfo
  }

  getToken(){
    if(!!this.getlocal("user") && !!!this.token){
      console.log("tokenLocak",this.getlocal("token"))
      this.token=this.getlocal("token");
      return this.token
    }else{
      return this.token;
    }
   
  }


  removeInfo(){
    //删除
    this.logInfo = {
      userName:"",
      mobile:"",
      registeAddress:"",
      idCard:"",
      nation:"",
      deleteMark:"",
      unitGuid:"",
      enabledMark:"",
      gender:"",
      birthday:"",
      headIcon:"",
    }
    this.token = ''
  }

  setlocal(key:string,value:any){
    //存储
    localStorage.setItem(key,JSON.stringify(value));
  }
  getlocal(key:string){
    console.log("-------------getlocal----------",key);
    console.log(localStorage.getItem(key));
    if(!!!localStorage.getItem(key)){
      return "";
    }else{
       //获取local中数据
      return JSON.parse(localStorage.getItem(key));
    }
  
  }

  removelocal(key:string){
    //删除数据
    localStorage.removeItem(key);
  }

}
